<template>
    <div>
        <el-container>
            <el-header class="homeHeader">
                <h3>V部博客管理平台</h3>
                <el-dropdown @command="userOperation">
                    <el-button type="primary">
                        {{loginer.username}}<i class="el-icon-arrow-down el-icon--right"></i>
                    </el-button>
                    <el-dropdown-menu slot="dropdown">
                        <el-dropdown-item command="userSettings">用户中心</el-dropdown-item>
                        <el-dropdown-item command="logout">注销</el-dropdown-item>
                    </el-dropdown-menu>
                </el-dropdown>
            </el-header>
            <el-container>
<!--                导航页面-->
                <el-aside width="200px">

                    <el-menu router>
                        <el-submenu :index="i+''" v-for="(item,i) in this.$router.options.routes" v-if="!item.hidden && item.meta.isChildOption">
                            <template slot="title">
                                <i :class="item.meta.icons"></i>
                                <span class="titleMargin">{{item.meta.title}}</span>
                            </template>
                            <el-menu-item :index="child.path" v-for="(child,index) in item.children">
                                <span slot="title">{{child.meta.title}}</span>
                            </el-menu-item>
                        </el-submenu>

                        <div v-for="(item,i) in this.$router.options.routes"  v-if="!item.hidden && !item.meta.isChildOption">
                            <el-menu-item :index="child.path" v-for="(child,index) in item.children">
                                <i :class="child.meta.icons"></i>
                                <span slot="title" class="titleMargin">{{child.meta.title}}</span>
                            </el-menu-item>
                        </div>
                    </el-menu>
                </el-aside>
<!--                主页面展示-->
                <el-main>
                    <el-breadcrumb separator-class="el-icon-arrow-right">
                        <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
                        <el-breadcrumb-item >{{this.$route.meta.title}}</el-breadcrumb-item>
                    </el-breadcrumb>
                     <router-view></router-view>
                </el-main>
            </el-container>
        </el-container>
    </div>
</template>

<script>
    export default {
        name: "Home",
        data(){
            return{
                loginer:JSON.parse(window.sessionStorage.getItem('loginer'))
            }
        },
        methods:{
            userOperation(command){
                if (command=='logout'){
                    this.$confirm('是否注销用户, 是否继续?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        window.sessionStorage.removeItem('loginer');
                        this.$message({
                            type: 'success',
                            message: '注销成功!'
                        });
                        this.$router.replace('/');
                    }).catch(() => {
                        this.$message({
                            type: 'info',
                            message: '已取消删除'
                        });
                    });
                }
            }
        },

    }
</script>

<style scoped>
    .homeHeader{
        background: #409eff;
        display: flex;
        color: #ffffff;

        justify-content: space-between;
        align-items: center;
    }
    .el-dropdown {
        vertical-align: top;
    }
    .el-dropdown + .el-dropdown {
        margin-left: 15px;
    }
    .el-icon-arrow-down {
        font-size: 12px;
    }
</style>